package com.xb.springtest.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

@Data
@ApiModel(description= "返回响应数据")
public class ReturnBody implements Serializable {
    
    private static final long serialVersionUID = 1L;

    private static final Integer SUCCESS = 0;
    private static final Integer FAIL = -1;

//    private Boolean isEncode = true;

    // @Fields code :返回值
    @ApiModelProperty(value = "响应码",required=true)
    private int code = SUCCESS;

    // @Fields descript : 返回描述
    @ApiModelProperty(value = "返回描述",required=false)
    private String desc = "请求执行成功！";
    // 实时状态 享家：1-2位用户状态 3-4位主关联房屋状态 5-6位备用 7-8位备用 9-10位备用
    // 享当家： 1-2位用户状态 3-4位关联区域状态（是否有审核通过的区域） 5-6位关联技能状态（是否用审核通过的技能） 7-8位指派工单权限
    // 9-10位关闭工单权限
    private String rts = "0000000000";

    /**
     * 检查点编码，用于特殊检查点的处理
     */
    @JsonIgnore
    private String checkpointCode;

    private String sign;

    // @Fields result : 返回结果
    @ApiModelProperty(value = "返回结果",required=false)
    private Object result;

//    public void setResponseCode(CodeDesc codeDesc) {
//        this.code = codeDesc.getCode();
//        this.desc = codeDesc.getDesc();
//    }

    public void setSuccess() {
        setCode(SUCCESS);
        setDesc("请求执行成功！");
    }

    public void setSuccess(String desc) {
        setCode(SUCCESS);
        setDesc(desc);
    }

    public void setFail() {
        setCode(FAIL);
        setDesc("请求执行失败！");
    }

    public void setFail(String desc) {
        setCode(FAIL);
        setDesc(desc);
    }

    public static ReturnBody fail(String desc) {
        ReturnBody returnBody = new ReturnBody();
        returnBody.setFail(desc);
        return returnBody;
    }

    public static ReturnBody fail(int code, String desc) {
        ReturnBody returnBody = new ReturnBody();
        returnBody.setDesc(desc);
        returnBody.setCode(code);
        return returnBody;
    }

    public static ReturnBody success(Object result) {
        ReturnBody returnBody = new ReturnBody();
        returnBody.setSuccess();
        returnBody.setResult(result);
        return returnBody;
    }

    public static ReturnBody success(String desc) {
        ReturnBody returnBody = new ReturnBody();
        returnBody.setSuccess(desc);
        return returnBody;
    }

    public static ReturnBody success(String desc, Object result) {
        ReturnBody returnBody = new ReturnBody();
        returnBody.setSuccess(desc);
        returnBody.setResult(result);
        return returnBody;
    }

}
